import { Injectable, Injector, Inject } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { DA_SERVICE_TOKEN, ITokenModel, ITokenService } from '@delon/auth';
import { environment } from '@env/environment';

@Injectable()
export class FileService {
  constructor(
    public http: _HttpClient, 
    @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
    ) {}

  download(path: string){
    let url = `${environment.SERVER_URL}${path}`;
    const tokenData: ITokenModel = this.tokenService.get() as ITokenModel;
    if (tokenData.token) {
      if(url.indexOf("?") == -1){
        url += `?access_token=${tokenData.token}`
      }else{
        url += `&access_token=${tokenData.token}`
      }
      
    }
    const a = document.createElement('a');
    a.href = url;
    a.target = '_blank'
    a.click();
  }

}
